<template>
	<view class="fy-left-tool">
		<view class="operate-block flex-center-column" v-if="mode&&mode=='day'">
			
			<!-- <button open-type="share" class="share-btn" plain style="border:0;">
				<image :src="shareIcon" style="width: 20px;height:20px;"></image>
			</button> -->
			<image :src="posterIcon" style="width: 20px;height:20px;margin-top: 1.5em;" @click="showPoster"></image>
			<image :src="moonIcon" style="width: 20px;height:20px;margin-top: 1.5em;" @click="changeMode"></image>
			<image v-if="baseConfig==0&&page=='home'" :src="setIcon" style="width: 20px;height:20px;margin-top: 1.5em;" @click="showSet"></image>
		</view>
		<view class="operate-block flex-center-column" v-if="mode&&mode=='night'">
			
			<!-- <button open-type="share" class="share-btn" plain style="border:0;">
				<image :src="shareIconNight" style="width: 20px;height:20px;"></image>
			</button> -->
			<image :src="posterIconNight" style="width: 20px;height:20px;margin-top: 1.5em;" @click="showPoster"></image>
			<image :src="sunIcon" style="width: 20px;height:20px;margin-top: 1.5em;" @click="changeMode"></image>
			<image v-if="baseConfig==0&&page=='home'" :src="setIconNight" style="width: 20px;height:20px;margin-top: 1.5em;" @click="showSet"></image>
		</view>
		<u-picker
			v-if="baseConfig==0"
			:show="showSetPicker" 
			:defaultIndex="[1]" 
			:columns="timeSpan" 
			closeOnClickOverlay
			@cancel="cancelPicker"
			:confirmColor="viewMode=='day'?'#3586ff':'#fcbf30'"
			@confirm="confirmPicker"
			@close="closePicker"
			@change="changeTimeSpan"></u-picker>
	</view>
</template>

<script>
	export default {
		name:"fy-left-tool",
		props:{
			page:{
				type:String,
				default:"home"
			},
			baseConfig:{
				type:Number,
				default:0
			},
			viewMode:{
				type:String,
				default:"night"
			}
		},
		watch:{
			viewMode:{
				handler(newVal){
					this.mode = newVal;
				}
			}
		},
		data() {
			return {
				time: null,
				timeSpan:[['5分钟','10分钟',"15分钟","30分钟","60分钟"]],
				mode:this.viewMode,
				setIcon:require("@/static/icon/set.png"),
				shareIcon:require("@/static/icon/share.png"),
				sunIcon:require("@/static/icon/sunshine.png"),
				shareIconNight:require("@/static/icon/share_night.png"),
				setIconNight:require("@/static/icon/set_night.png"),
				moonIcon:require("@/static/icon/moon.png"),
				posterIcon:require("@/static/icon/poster.png"),
				posterIconNight:require("@/static/icon/poster_night.png"),
				showSetPicker:false
			};
		},
		methods:{
			showPoster(){
				this.$emit("showPoster",true);
			},
			confirmPicker(e){
				this.showSetPicker = false;
				switch(e.indexs[0]){
					case 0:
						this.minutes = 5;
						break;
					case 1:
						this.minutes = 10;
						break;
					case 2:
						this.minutes = 15;
						break;
					case 3:
						this.minutes = 30;
						break;
					case 4:
						this.minutes = 60;
						break;
				}
				uni.setStorageSync("minutes",this.minutes)
				this.$emit("updateTime",this.minutes);
			},
			changeTimeSpan(e){
				
			},
			changeMode(){
				if(this.mode=='day'){
					this.mode = "night";
				}else{
					this.mode = 'day';
				}
				uni.setStorageSync("mode",this.mode);
				this.$emit("update:viewMode",this.mode);
			},
			cancelPicker(){
				this.showSetPicker = false;
			},
			closePicker(){
				this.showSetPicker = false;
			},
			showSet(){
				this.showSetPicker = true;
			},
			
		}
	}
</script>

<style scoped lang="scss">
	.fy-left-tool {
		.operate-block {
			
			.share-btn {
				width: 60px;
				height: 20px;
				background-color: rgba(0, 0, 0, 0);
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>